package com.example07.entities;

public class TicketPoint extends Thread{
    private String pointName;
    private int sell = 0;
    public TicketPoint(String pointName) {
        this.pointName = pointName;
    }
    public String getPointName() {
        return pointName;
    }

    public void setPointName(String pointName) {
        this.pointName = pointName;
    }

    public int getSell() {
        return sell;
    }

    public void setSell(int sell) {
        this.sell = sell;
    }

    @Override
    public void run() {
        this.getTicket();
    }

    public void getTicket() {
        Railways railways = new Railways();
        while (true) {
            synchronized (this) {
                Ticket ticket = railways.sellTicket();
                if (ticket != null) {
                    sell++;
                } else {
                    System.out.println(this.pointName + "票卖光了");
                    System.out.println(this.pointName +"总共卖出了"+ sell + "张票");
                    break;
                }
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.getMessage();
                }
                System.out.println(this.pointName +"卖出了"+ sell + "张票");
            }
        }
    }
}
